﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuanLyDuocPham.View.QuanLyHeThong.DanhMuc;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;

namespace QuanLyDuocPham.Controllers.UC.QuanLyHeThong.DanhMuc
{
    /// <summary>
    /// Interaction logic for UC_QUAY_List.xaml
    /// </summary>
    public partial class UC_QUAY_List : UserControl
    {
        public UC_QUAY_List()
        {
            InitializeComponent();
        }
        QUAY_Control quctrl = new QUAY_Control();
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            loadData();
        }
        private void loadData()
        {
            quctrl.loadData(dataPager1);
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            QUAYTN_Add_View adddp = new QUAYTN_Add_View();
            adddp.done = new QUAYTN_Add_View.added(loadData);
            adddp.ShowDialog();
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (lv_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn quầy cần sửa!");
            }
            else
            {
                QUAYTN_Edit_View edit = new QUAYTN_Edit_View();
                string[] select_item = new string[4];
                select_item = quctrl.get_item(lv_List);
                edit._ma_nhathuoc = select_item[0];
                edit._ma_quay = select_item[1];
                edit.done = new QUAYTN_Edit_View.added(loadData);
                edit.ShowDialog();
            }
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (lv_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn quầy cần xóa!");
            }
            else
            {       string[] select_item = new string[4];
                    select_item=quctrl.get_item(lv_List);
                    if (MessageBox.Show("Bạn có chắc chắn muốn xóa quầy " + select_item[2] + " thuộc nhà thuốc " + select_item[3], "Cảnh báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        quctrl.deleteData(select_item[0], select_item[1]);

                    }
            
            }
            loadData();

        }

    }
}
